#include "Player.h"

Player::Player( Handle camera ) 
	:mCamera(camera),
	mTarget(0)
{
	mAttributes.Speed(.5f);
	xEntityColor(mesh, 0, 255, 0);
	DefaultCameraOffset();
}

Player::Player(Handle camera, float speed, Color clr) 
	:mCamera(camera),
	mTarget(0)
{
	mAttributes.Speed(speed);
	xEntityColor(mesh, clr.R, clr.G, clr.B);
	DefaultCameraOffset();
}

void Player::UpdateCamera()
{
	Vec3D camPosition(xEntityX(mesh, true), xEntityY(mesh, true), xEntityZ(mesh, true));
	CameraOffset offset = DefaultCameraOffset();

	camPosition += offset.mPosition;
	xPositionEntity(mCamera, camPosition.x, camPosition.y, camPosition.z);
	
	Vec3D camRotation = offset.mRotation;

	xRotateEntity(mCamera, camRotation.x, camRotation.y, camRotation.z, true);
}

void Player::Target( Character* target )
{
	mTarget = target;
}

void Player::Update()
{
	UpdateCamera();
}

Player::CameraOffset Player::DefaultCameraOffset()
{
	CameraOffset offset;
	offset.mPosition = Vec3D(0, 50, -50);
	offset.mRotation = Vec3D(45, 0, 0);
	return offset;
}
